#ifndef __BSP_USART_H
#define __BSP_USART_H

#ifdef __cplusplus
extern "C" {
#endif

#include "mm32_device.h"
#include "hal_conf.h"


#define UART_NUM 1

typedef struct uart_gpio
{
	uint8_t pin_source;
	uint8_t pin_af;
	uint16_t pin;
	GPIO_TypeDef *gpio;
}uart_gpio;


typedef struct uart_module
{
	UART_WordLength_TypeDef wordlength;
	UART_Stop_Bits_TypeDef stopbits;
	UART_Parity_TypeDef parity;
	uint16_t mode;
	UART_HW_FLOWCONTROL_TypeDef hardwareflowcontrol;
	uint32_t baudrate;
	UART_TypeDef *uartx;
}uart_module;

typedef struct uart_dma
{
    uint8_t *memoryaddr;
    uint32_t bufsize;
    DMA_priority_level_TypeDef priority;
	UART_TypeDef *uartx;
	DMA_Channel_TypeDef *dma_chx;
}uart_dma;


typedef struct tag_uart_para
{
	uint8_t *rxbuff;
	uint8_t *txbuff;
	uint32_t last_dmarx_size;
	uint32_t rx_buf_size;
	uint32_t tx_buf_size;
}uart_para_t;



#define UART3_CLK_ENABLE()		

#define UART3_TX_PORT           GPIOD
#define UART3_TX_PIN            GPIO_Pin_8
#define UART3_TX_PINSOURCE 		GPIO_PinSource8
#define UART3_TX_PINAF	 		GPIO_AF_7


#define UART3_RX_PORT      		GPIOD
#define UART3_RX_PIN            GPIO_Pin_9
#define UART3_RX_PINSOURCE 		GPIO_PinSource9
#define UART3_RX_PINAF	 		GPIO_AF_7

#define	UART3_FIFO_EN	1

#if UART3_FIFO_EN
	#define UART3_BAUD			115200
	#define UART3_TX_BUF_SIZE	1*512
	#define UART3_RX_BUF_SIZE	1*512
#endif


#define uart_gpio_clkopen() {	\
    RCC_AHBPeriphClockCmd(RCC_AHBENR_GPIOD, ENABLE);	\
};


#define uart_clkopen() {	\
	RCC_APB1PeriphClockCmd(RCC_APB1ENR_UART3, ENABLE);	\
};


void comsendbuf(DMA_Channel_TypeDef *dmachx, uint8_t *pdata, uint16_t size);
void myprintf(const char *fmt, ...);

void bsp_uartinit(void);
extern uart_para_t uart_para3;

#ifdef __cplusplus
}
#endif

#endif


